<template>
	<view class="">
		<view class="has-pd-20 is-size-16 is-blue-color has-bg-white">
			<view class="s-row">
				<view class="is-col-10">
					成员
				</view>
				<view class="is-col-6 is-center">
					业绩（万）
				</view>
				<view class="is-col-4 is-right">
					收益
				</view>
				<view class="is-col-4 is-right">
					状态
				</view>
			</view>
		</view>
		<view class="has-pdlr-20 has-pdtb-15 is-size-14 has-bordert is-bold-no has-bg-white" v-for="(item,index) in list" :key="index">
			<view class="s-row">
				<view class="is-col-10">
					{{item.user_name}}
				</view>
				<view class="is-col-6 is-center">
					{{item.income_num}}
				</view>
				<view class="is-col-4 is-center">
					{{item.income_agent_num}}
				</view>
				<view class="is-col-4 is-right" :class="itme.income_agent_lock ? '':'is-red'">
					{{item.income_agent_tit}}
				</view>
			</view>
		</view>
		<view style="flex: 1;">
			<uni-err-box  :errType="errType" :errText="errText" ></uni-err-box>
		</view>
		<view style="flex: 1;">
			<uni-load-more  :loadingType="loadingType" :contentText="contentText" ></uni-load-more>
		</view>
	</view>
</template>

<script>
	import uniLoadMore from '@/components/load-more.vue';
	import uniErrBox from '@/components/err-box.vue';
	var _self,
		page = 1,
		timer = null;
	export default {
		components: {
			uniLoadMore,
			uniErrBox
		},
		data(){
			return{
				foxtoken:'',
				errType: 0,
				errText: '',
				list:[],
				loadingText: '加载中...',
				loadingType: 0,//定义加载方式 0---contentdown  1---contentrefresh 2---contentnomore
				contentText: {
					contentdown:'上拉显示更多',
					contentrefresh: '正在加载...',
					contentnomore: '没有更多了'
				}
			}
		},
		onLoad() {
			_self = this;
			let info = this.service.getfox();
			if(info[0]){
				this.foxtoken = info[0]['foxtoken'];
			}else{
				uni.reLaunch({
					url:'../logon/login'
				})
			}
			this.getList();
		},
		//下拉刷新
		onPullDownRefresh: function() {
			this.getList();
		},
		// 加载更多
		onReachBottom : function(){
			if (timer != null) {
				clearTimeout(timer);
			}
			timer = setTimeout(function() {
				_self.getmore();
			}, 1000);
		},
		methods: {
			// 数据和分页是模拟的实际也是这样写
			getmore: function(){
				if (_self.loadingType !== 0) {//loadingType!=0;直接返回
					return false;
				}
				_self.loadingType = 1;
				uni.showNavigationBarLoading();//显示加载动画
				uni.request({
					url: this.service.FOX_URL + 'diamond/income_list',
					method:'POST',
					data: {
						page:page,
						limit:10,
						user_key:this.foxtoken
					},
					dataType:'json',
					header:{
						'content-type':'application/x-www-form-urlencoded'
					},
					success: res => {
						var foxmsg = res.data;
						if (foxmsg.data.list == null  || foxmsg.data.list.length==0) {//没有数据
							_self.loadingType = 2;
							uni.hideNavigationBarLoading();//关闭加载动画
							return;
						}
						page++;//每触底一次 page +1
						_self.list = _self.list.concat(foxmsg.data.list);//将数据拼接在一起
						_self.loadingType = 0;//将loadingType归0重置
						uni.hideNavigationBarLoading();//关闭加载动画
					},
					complete: res => {
						uni.hideLoading();
						uni.stopPullDownRefresh();
					}
				});
			},
			getList: function() {//第一次回去数据
				page = 1;
				this.loadingType = 0;
				uni.showNavigationBarLoading();
				uni.request({
					url: this.service.FOX_URL + 'diamond/income_list',
					method:'POST',
					data:{
						page:page,
						limit:10,
						user_key:this.foxtoken
					},
					dataType:'json',
					header:{
						'content-type':'application/x-www-form-urlencoded'
					},
					success: res => {
						page++;//得到数据之后page+1
						var foxmsg = res.data;
						// console.log(foxmsg)
						if (foxmsg.code == 200) {                    
							_self.list = foxmsg.data.list;
							if (foxmsg.data.list.length > 0 && foxmsg.data.list.length < 10) {//没有数据
								_self.loadingType = 5;
								uni.hideNavigationBarLoading();//关闭加载动画
								return;
							}
							if (foxmsg.data.list.length == 0) {
								_self.errType = 1;
								_self.loadingType = 4;
								uni.hideNavigationBarLoading();//关闭加载动画
								return;
							}
							uni.hideNavigationBarLoading();
							uni.stopPullDownRefresh();//得到数据后停止下拉刷新
						}else{
							_self.errType = 1;
							_self.loadingType = 4;
							uni.hideNavigationBarLoading();//关闭加载动画
							return;
						}                         
					}
				});
			}
		}	
	}
</script>

<style>
</style>
